/**
 * @ClassName: Message
 * @Description:
 * @author congqing
 * @date 2019-11-13 20:22
 */
package net.alpcontrol.bi.bootstrap.bean;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @ClassName: Message
 * @Description:
 * @author congqing
 * @date 2019-11-13 20:22
 *
 */
@Data
@ApiModel(value="请求返回结果对象", description="请求返回结果对象")
public class Message<T> {

    public static final String SUCCESS_DEFAULT_CODE = "200";
    public static final String FAILURE_DEFAULT_CODE = "101";

    @ApiModelProperty(value = "结果标识")
    private Boolean success;
    @ApiModelProperty(value = "结果编码")
    private String code = "200";
    @ApiModelProperty(value = "结果消息")
    private String message;
    @ApiModelProperty(value = "结果数据")
    private T data;

    public Message() {
        this.success = false;
    }

    public Message(Boolean success, String code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
    }

    public Message(Boolean success, String message) {
        this.success = success;
        this.message = message;
    }

    public Message(Boolean success, String message, T data) {
        this.success = success;
        this.message = message;
        this.data = data;
    }

    public Message(Boolean success, String code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static Message success(String code, String message, Object data) {
        return new Message(true, code, message, data);
    }

    public static Message success(String message, Object data) {
        return new Message(true, SUCCESS_DEFAULT_CODE, message, data);
    }

    public static Message success(String message) {
        return new Message(true, SUCCESS_DEFAULT_CODE, message);
    }

    public static Message success(Object data) {
        return new Message(true, SUCCESS_DEFAULT_CODE, "操作成功", data);
    }

    public static Message success() {
        return new Message(true, SUCCESS_DEFAULT_CODE, "操作成功");
    }

    public static Message saveSuccess() {
        return new Message(true, SUCCESS_DEFAULT_CODE, "保存成功");
    }

    public static Message updateSuccess() {
        return new Message(true, SUCCESS_DEFAULT_CODE, "修改成功");
    }

    public static Message deleteSuccess() {
        return new Message(true, SUCCESS_DEFAULT_CODE, "删除成功");
    }

    public static Message failure(String code, String message) {
        return new Message(false, code, message);
    }

    public static Message failure(String code, String message, Object data) {
        return new Message(false, code, message, data);
    }

    public static Message failure(String message, Object data) {
        return new Message(false, FAILURE_DEFAULT_CODE, message, data);
    }

    public static Message failure(String message) {
        return new Message(false, FAILURE_DEFAULT_CODE, message);
    }

    public static Message failure() {
        return new Message(false, FAILURE_DEFAULT_CODE, "操作失败");
    }

    public static Message failureWithNullParameters() {
        return new Message(false, FAILURE_DEFAULT_CODE, "参数不能为空");
    }

    public static Message failureWithInvalidParameters() {
        return new Message(false, FAILURE_DEFAULT_CODE, "无效的参数");
    }

    public static Message failureWithNotLogin() {
        return new Message(false, FAILURE_DEFAULT_CODE, "用户没有登录或登录已过期");
    }

}